package cn.piaoyi.service.imp;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import org.apache.commons.logging.*;

import cn.piaoyi.bean.Admin;
import cn.piaoyi.dao.AdminDAO;
import cn.piaoyi.exception.PiaoyiException;
import cn.piaoyi.service.AdminService;


public class AdminServiceImp implements AdminService {

	private static final Log logger = LogFactory.getLog(AdminServiceImp.class);
	
	private AdminDAO adminDAO;

	public AdminDAO getAdminDAO() {
		return adminDAO;
	}

	public void setAdminDAO(AdminDAO adminDAO) {
		this.adminDAO = adminDAO;
	}

	/**
	 * 保存Admin对象
	 * 
	 * @param admin
	 * 			Admin对象
	 * @return Admin
	 * 			Admin对象
	 */
	public Admin createAdmin(Admin admin) throws PiaoyiException{
		try {
			admin = this.getAdminDAO().saveAdmin(admin);
			return admin;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}
	
	/**
	 * 根据username获取Admin对象
	 * 
	 * @param username
	 * 			String
	 * @return Admin
	 * 			Admin对象
	 */
	public Admin findAdminByUsername(String username){
		return this.getAdminDAO().findAdminByUsername(username);
	}
	
	/**
	 * 保存Admin对象
	 * 
	 * @param admin
	 * 			Admin对象
	 * @return Admin
	 * 			Admin对象
	 */
	public Admin updateAdmin(Admin admin) throws PiaoyiException{
		try {
			admin = this.getAdminDAO().updateAdmin(admin);
			return admin;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}
	
	/**
	 * 根据主键ID获取Admin对象
	 * 
	 * @param id
	 * 			主键ID
	 * @return Admin
	 * 			Admin对象
	 */
	public Admin findAdminById(long id){
		return this.getAdminDAO().findAdminById(id);
	}
	
	/**
	 * 获取Admin列表
	 * 
	 * @param orderby
	 *            String
	 * @param ascOrDesc
	 *            int
	 * @return List
	 * 			Admin对象列表
	 */
	public List findAdmins(String orderby, int ascOrDesc){
		return this.getAdminDAO().findAdmins(orderby, ascOrDesc);
	}
	
	/**
	 * 删除Admin对象
	 */
	public void removeAdminById(long id){
		this.getAdminDAO().removeAdminById(id);
	}
}
